<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Faceless man - JSVMP</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/5.1.3/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/codemirror/5.40.2/codemirror.min.js"></script>
    <link rel="stylesheet" href="https://cdn.staticfile.org/codemirror/5.40.2/codemirror.min.css">
    <script src="https://cdn.staticfile.org/codemirror/5.40.2/addon/edit/closebrackets.min.js"></script>
    <script src="https://cdn.staticfile.org/split.js/1.6.5/split.min.js"></script>
    <script src="https://cdn.staticfile.org/downloadjs/1.4.8/download.min.js"></script>
    <script src="tools/babelPlugins.js"></script>
    <script src="test/main.js"></script>

    <style>
        body {
            background: #f6f6f6;
        }

        .split {
            display: flex;
            flex-direction: row;
        }


        #iframeResult {
            display: block;
            height: 100%;
            width: 100%;
        }

        .gutter {
            background-color: #f6f6f6;
            background-repeat: no-repeat;
            background-position: 50%;
        }

    </style>
</head>
<body>

<div class="container-fluid pb-3">
    <div class="split">
        <div id="split-0" class="bg-body rounded shadow-sm">
            <div class="card">
                <div class="card-header">
                    <!--                    <button type="button" onclick="pasteCode()" class="btn btn-outline-secondary">粘贴源码</button>-->
                    <button type="button" class="btn btn-success float-end" onclick="reinforce()" id="submitBTN">
                        执行加固
                    </button>
                </div>
                <div class="card-body" style="padding:0">
                    <textarea class="form-control" id="textareaCode" name="textareaCode" wrap="virtual">// 将待加固的源代码粘贴到框框中,单击执行加固即可！</textarea>
                </div>
            </div>
        </div>
        <div id="split-1" class="bg-body rounded shadow-sm">
            <div class="card">
                <div class="card-header">
                    <button type="button" class="btn btn-outline-secondary" onclick="downloadCode()">下载代码</button>
                    <button type="button" class="btn btn-outline-secondary" onclick="copyCode()">
                        复制代码
                    </button>
                </div>
                <div class="card-body" style="padding:0">
                    <textarea class="form-control" id="textareaCodeJsvmp" name="textareaCodeJsvmp" wrap="virtual">console.log("test")</textarea>
                </div>
            </div>
        </div>
    </div>

    <footer class="py-1 my-2">
        <div class="text-center border-bottom pb-2">
            <!-- 移动版 自动调整 -->
            <ins class="adsbygoogle"
                 style="display:block"
                 data-ad-client="ca-pub-5751451760833794"
                 data-ad-slot="1691338467"
                 data-ad-format="auto"
                 data-full-width-responsive="true"></ins>
        </div>

        <p class="text-center text-muted p-2">2023 - Faceless man (Public) - <a target="_blank"
                                                                                href="https://github.com/Alanhays/facelessJsvmp">无脸男JSVMP</a>
        </p>
        <p class="text-center text-muted p-2">注: 由于项目开源导致加固代码很容易被反编译, 请勿将加固后的代码用于生产环境。</p>
    </footer>
</div>
<script>
    var mixedMode = {
        name: "htmlmixed",
        scriptTypes: [{
            matches: /\/x-handlebars-template|\/x-mustache/i,
            mode: null
        },
            {
                matches: /(text|application)\/(x-)?vb(a|script)/i,
                mode: "vbscript"
            }]
    };

    var editor = CodeMirror.fromTextArea(document.getElementById("textareaCode"), {
        mode: mixedMode,
        selectionPointer: true,
        lineNumbers: true,
        matchBrackets: true,
        indentUnit: 4,
        indentWithTabs: true
    });

    let jsvmp = CodeMirror.fromTextArea(document.getElementById("textareaCodeJsvmp"), {
        mode: mixedMode,
        selectionPointer: true,
        lineNumbers: true,
        matchBrackets: true,
        indentUnit: 4,
        indentWithTabs: true
    });

    window.addEventListener("resize", autodivheight);

    var x = 0;

    function autodivheight() {
        var winHeight = 0;
        if (window.innerHeight) {
            winHeight = window.innerHeight;
        } else if ((document.body) && (document.body.clientHeight)) {
            winHeight = document.body.clientHeight;
        }
        //通过深入Document内部对body进行检测，获取浏览器窗口高度
        if (document.documentElement && document.documentElement.clientHeight) {
            winHeight = document.documentElement.clientHeight;
        }
        height = winHeight * 0.68 + 4
        editor.setSize('100%', height + 28);
        jsvmp.setSize('100%', height + 28);
    }

    window.copyCode = function () {
        let input = document.createElement('input');
        input.type = 'text';
        input.value = jsvmp.getValue();
        document.body.appendChild(input);
        try {
            input.select();
            document.execCommand('copy');
            document.body.removeChild(input);
        } catch (error) {
        }
    }

    window.pasteCode = function () {

    }

    function reinforce() {
        let jsvmp_code;
        try {
            jsvmp_code = virtualizationSourceCode(editor.getValue());
        } catch (e) {
            jsvmp_code = e.message;
        }
        jsvmp.setValue(jsvmp_code)
    }

    autodivheight();
    Split(['#split-0', '#split-1']);

    function downloadCode() {
        download(jsvmp.getValue(), `FacelessManJSVMP-${Number(Date.now())}.js`, "text/js");
    }

</script>
</body>
</html>